/*var app = angular.module('conversionTool', [ 'ui.bootstrap','smart-table' ]);*/


var app = angular.module('conversionTool', ['smart-table']);

app.controller('dataAdaptorManagerCtrl', [ '$scope', '$http', function($scope, $http) {
	
	
	$scope.dataTypeItems = [ 'CSV','EXCEL', 'XML', 'DataBase' ];

	$scope.dataAdaptors =[];
	
	$scope.itemsByPage=10;
	
	$scope.dataAdaptorsDisplay=[].concat($scope.dataAdaptors);

	$scope.initial = function() {
		$http.post('/rest/dataAdaptor/getAllDataAdaptor').success(function(data) {

			$scope.dataAdaptors = data;
			
			$scope.dataAdaptorsDisplay=[].concat($scope.dataAdaptors);

		}).error(function(data) {
			console.log(data);
		});

	}

	$scope.initial();

	$scope.showDetail = function(id, dataType) {
		
		switch (dataType) {
		case $scope.dataTypeItems[0]:
			$scope.actionURL = "csvType";
			break;
		case $scope.dataTypeItems[1]:
			$scope.actionURL = "excelType";
			break;
		case $scope.dataTypeItems[2]:
			$scope.actionURL = "xmlType";
			break;
		case $scope.dataTypeItems[3]:
			$scope.actionURL = "dataBaseType";
			break;
		}
		
		$scope.dataAdaptorId=id;
		
		document.getElementById("dataAdaptorId").value=id;

	}

	$scope.deleteDataAdaptor = function(id) {

		$http.post('/rest/dataAdaptor/deleteDataAdaptor', {
			"id" : id
		}).success(function(data) {

			$scope.initial();
			$scope.msg = "delete success!";

		}).error(function(data) {
			console.log(data);
		});

	}

} ]);